import { reactive, computed } from "vue";
import { defineStore } from "pinia";
import { getInfo } from "@/api/manage.js";
// import { useRouter } from 'vue-router'
// const router = useRouter();
export const userAdminStore = defineStore("admin", () => {
	// 定义状态
	let adminState = reactive({
		adminInfo: {},
		isCollapse: false,
		iconFont: "Fold",
		logoUrl: "/src/assets/logo.png",
	});

	// 定义计算属性
	const menus = computed(() => {
		return adminState.adminInfo.menus;
	});
	function getAdminInfo() {
		return getInfo()
			.then((res) => {
				adminState.adminInfo = res;
			})
			.catch((err) => {
				console.log(err);
			});
	}
	function setIsCollapse() {
		let bool = !adminState.isCollapse;
		adminState.isCollapse = !adminState.isCollapse;
		adminState.iconFont = bool ? "Expand" : "Fold";
		// 改变logo
		adminState.logoUrl = bool
			? "/src/assets/logo1.png"
			: "/src/assets/logo.png";
	}

	// asyncRoutes,
	return { adminState, getAdminInfo, menus, setIsCollapse };
});
